# 中文与gbk编码相互转化
# decode 解码 encode 编码
st1 = '明天'
# 按照utf-8把字符串编码为Unicode
st1_unicode = st1.encode('utf-8')
print(st1_unicode)
# 按照gbk把Unicode字符串解码为字符串
st1_gbk = st1_unicode.decode('gbk')
print(st1_gbk)
print('--'*40)

# 中文与gb2312相互转化
st2 = '明天'
st2_gb2312 = st2.encode('gb2312')
print(st2_gb2312)
st2_zw = st2_gb2312.decode('gb2312')
print(st2_zw)
print('--'*40)

# 中文与utf8相互转化
st3 = '明天'
st3_utf8 = st3.encode('utf-8')
print(st3_utf8)
st3_zw = st3_utf8.decode('utf-8')
print(st3_zw)
print('--'*40)

# 中文与url码相互转化
# 将中文转换为url码
from urllib.parse import quote
st4 = '明天'
st4_url = quote(st4)
print(st4_url)
# 将url码转换为中文
from urllib.parse import unquote
print(unquote(st4_url, encoding='utf-8'))